<template>
  <div class="swiper">
    <swiper :options="swiperOption" v-if="showSwiper">
      <!-- slides -->
      <swiper-slide v-for="item in list" :key="item.id">
        <img class="swiper-img" :src="item.imgUrl" alt="" />
      </swiper-slide>
      <!-- Optional controls -->
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: "HomeSwiper",
  props: {
    list: Array
  },
  data() {
    return {
      swiperOption: {
        loop: true,
        pagination: {
          el: ".swiper-pagination",
          type: "bullets"
        }
      }
    };
  },
  computed: {
    showSwiper() {
      return this.list.length;
    }
  }
};
</script>

<style lang="stylus" scoped>
.swiper {
  // 根据图片宽高比例设置图片宽高比例自适应
  // 可以解决网络不好图片加载慢时，图片加载前后内容跳动的问题
  overflow: hidden
  width: 100%
  height: 0
  padding-bottom: 26.66%
  background-color: #eee
  >>> .swiper-pagination-bullet-active {
    background-color: #fff
  }
  .swiper-img {
    width: 100%
  }
}
</style>
